﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

using MINERP.ComControls;
using MINERP.COM;

using MINERP.BLL.GenerateReports;
namespace MINERP.InfoConfig
{
    public partial class FrmInfoConfig : FrmParent
    {
        private static FrmInfoConfig instance = null;
        FrmUserManager frmUserManager = null;
        FrmUserRoleManager frmUserRoleManager = null;
        FrmPrinterManager frmPrinterManager = null;
        FrmShopManager frmShopManager = null;
        FrmAreaManager frmAreaManager = null;
        FrmPaperPaceManager frmPaperPaceManager = null;
        FrmPaperTypeManager frmPaperTypeManager = null;
        FrmTemplateManager frmTemplateManager = null;
        FrmFolderManager frmFolderManager = null;
        FrmProductManager frmProductManager = null;
        FrmDelegateManager frmDelegateManager = null;

        FrmActionManager frmAction = null;
        FrmBordWidthManager frmBordWidth = null;
        FrmCostTypeManager frmPriceCategory = null;
        FrmProductCategoryManager frmProductCategory = null;
        FrmProductTypeManager frmProductType = null;
        FrmTechManager frmTech = null;
        FrmWorkerGroup frmWorkerGroup = null;
        FrmUpdate frmUpdate = null;
        FrmShopTechUserManager frmShopTechUserManager = null;
        FrmProductOutShopManager frmProductOutShopManager = null;
        FrmSalesmanManager frmSalesmanManager = null;
        FrmProductCommomItem frmProductCommomItem=null;
        FrmComplexSet frmComplexset = null;
        private FrmTechCommomChargeItem frmTechCommomCharge = null;

        private FrmShippingManager frmShippingManager = null;

        StatisticsBLL _bll = new StatisticsBLL();
        //FrmDBManage frmDBManager = null;
        FrmProsessBar frmBar = null;
        delegate void CloseBar();
    
        public FrmInfoConfig()
        {
            InitializeComponent();
            base.InitiAuthority();
        }

        public static FrmInfoConfig CreateInstance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmInfoConfig();
                }
                return instance;
            }
        
        }
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Hide();
        }
        private void barButtonDbConfig_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //FrmDBManage frmDBManage = FrmDBManage.CreateInstance;
            //frmDBManage.Show();
        }
        #region 菜单
        //用户基本信息
        private void nBarUserbaseInfo_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            frmUserManager = FrmUserManager.CreateInstance;
            frmUserManager.MdiParent = this;
            frmUserManager.WindowState = FormWindowState.Maximized;
            frmUserManager.Show();
        }
        //用户角色权限
        private void nBarUserrole_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmUserRoleManager = FrmUserRoleManager.CreateInstance;
            frmUserRoleManager.MdiParent = this;
            frmUserRoleManager.WindowState = FormWindowState.Maximized;
            frmUserRoleManager.Show();
        }
        //打印机

        private void navBarPrinter_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmPrinterManager = FrmPrinterManager.CreateInstance;
            frmPrinterManager.MdiParent = this;
            frmPrinterManager.WindowState = FormWindowState.Maximized;
            frmPrinterManager.Show();

        }
        //分区
        private void navBarArea_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmAreaManager = FrmAreaManager.CreateInstance;
            frmAreaManager.MdiParent = this;
            frmAreaManager.WindowState = FormWindowState.Maximized;
            frmAreaManager.Show();
        }
        //纸型
        private void navBarPaperType_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmPaperTypeManager = FrmPaperTypeManager.CreateInstance;
            frmPaperTypeManager.MdiParent = this;
            frmPaperTypeManager.WindowState = FormWindowState.Maximized;
            frmPaperTypeManager.Show();
        }
        //纸面
        private void navBarPaperPace_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmPaperPaceManager = FrmPaperPaceManager.CreateInstance;
            frmPaperPaceManager.MdiParent = this;        
            frmPaperPaceManager.WindowState = FormWindowState.Maximized;
            frmPaperPaceManager.Show();
        }
        //模版
        private void navBarTemplate_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmTemplateManager = FrmTemplateManager.CreateInstance;
            frmTemplateManager.MdiParent = this;     
            frmTemplateManager.WindowState = FormWindowState.Maximized;
            frmTemplateManager.Show();

        }
        //商户
        private void navBarShop_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmShopManager = FrmShopManager.CreateInstance;
            frmShopManager.MdiParent = this;
            frmShopManager.WindowState = FormWindowState.Maximized;
            frmShopManager.Show();
        }

        //商户默认节点操作员设定
        private void navBarShopTechUser_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmShopTechUserManager = FrmShopTechUserManager.GetInstance;
            frmShopTechUserManager.MdiParent = this;
            frmShopTechUserManager.WindowState = FormWindowState.Maximized;
            frmShopTechUserManager.Show();
        }
        //文件夹

        private void navBarFolder_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmFolderManager = FrmFolderManager.CreateInstance;
            frmFolderManager.MdiParent = this;
            frmFolderManager.WindowState = FormWindowState.Maximized;
            frmFolderManager.Show();

        }
        //产品
        private void navBarProduct_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmProductManager = FrmProductManager.CreateInstance;
            frmProductManager.MdiParent = this;
            frmProductManager.WindowState = FormWindowState.Maximized;
            frmProductManager.Show();
        }   
        //委外加工
        private void navBardelegate_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmDelegateManager = FrmDelegateManager.CreateInstance;
            frmDelegateManager.MdiParent = this;
            frmDelegateManager.WindowState = FormWindowState.Maximized;
            frmDelegateManager.Show();
        }
        //产品默认委外商
        private void navBarProductOutShop_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmProductOutShopManager = FrmProductOutShopManager.GetInstance;
            frmProductOutShopManager.MdiParent = this;
            frmProductOutShopManager.WindowState = FormWindowState.Maximized;
            frmProductOutShopManager.Show();
             
        }
        //节点
        private void navBarTech_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmTech = FrmTechManager.CreateInstance;
            frmTech.MdiParent = this;
            frmTech.WindowState = FormWindowState.Maximized;
            frmTech.Show();
        }
        //计价类型
        private void navBarPriceCategory_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmPriceCategory = FrmCostTypeManager.CreateInstance;
            frmPriceCategory.MdiParent = this;
            frmPriceCategory.WindowState = FormWindowState.Maximized;
            frmPriceCategory.Show();

        }
        //产品分类
        private void navBarProductCategory_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmProductCategory = FrmProductCategoryManager.CreateInstance;
            frmProductCategory.MdiParent = this;
            frmProductCategory.WindowState = FormWindowState.Maximized;
            frmProductCategory.Show();
        }
        //产品类型
        private void navBarProductType_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmProductType = FrmProductTypeManager.CreateInstance;
            frmProductType.MdiParent = this;
            frmProductType.WindowState = FormWindowState.Maximized;
            frmProductType.Show();
        }
        //操作
        private void navBarAction_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmAction = FrmActionManager.CreateInstance;
            frmAction.MdiParent = this;
            frmAction.WindowState = FormWindowState.Maximized;
            frmAction.Show();
        }
        //纸型宽度
        private void navBarBordWidth_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmBordWidth = FrmBordWidthManager.CreateInstance;
            frmBordWidth.MdiParent = this;
            frmBordWidth.WindowState = FormWindowState.Maximized;
            frmBordWidth.Show();
        }
        // 工作组

        private void navBarWorkerGroup_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmWorkerGroup = FrmWorkerGroup.GetInstance;
            frmWorkerGroup.MdiParent = this;
            frmWorkerGroup.WindowState = FormWindowState.Maximized;
            frmWorkerGroup.Show();

        }
        //程序更新设置
        private void navBarUPdate_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmUpdate = new FrmUpdate();
            frmUpdate.MdiParent = this;
            frmUpdate.WindowState = FormWindowState.Maximized;
            frmUpdate.Show();
        }
        //拼版数据清除
        private void navBarClearPinBanData_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            FrmDataClear frmDataClear = FrmDataClear.GetInstance;
            frmDataClear.MdiParent = this;
            frmDataClear.WindowState = FormWindowState.Maximized;
            frmDataClear.Show();
           
        }

        // 公共收费项目
        private void navbarComChargeItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            FrmComChargeItem frm = FrmComChargeItem.Instance;
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();

        }
        //商户ftp上传
        private void navBarShopFtp_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
   
        }
        //警报信息
        private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

            CloseMDIForm();
            FrmAlarmReceiver frmAlarmReceive = FrmAlarmReceiver.GetInstance;
            frmAlarmReceive.MdiParent = this;
            frmAlarmReceive.WindowState = FormWindowState.Maximized;
            frmAlarmReceive.Show();
        }
        //车间信息
        private void navBarItem3_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            FrmWorkShop frmWorkShop = new FrmWorkShop();
            frmWorkShop.MdiParent = this;
            frmWorkShop.WindowState = FormWindowState.Maximized;
            frmWorkShop.Show();
        }
        #endregion

        private void CloseMDIForm()
        {
            List<Form> formList = this.MdiChildren.ToList();
            foreach (var item in formList)
            {
                item.Close();
            }
        }
        private void FrmInfoConfig_Load(object sender, EventArgs e)
        {
           
        }

        private void FrmInfoConfig_FormClosing(object sender, FormClosingEventArgs e)
        {
            MINERP.COM.Logoff.ShowMainFrm(); 
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            this.Close();
            MINERP.COM.Logoff.ShowMainFrm();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            //Cursor = Cursors.WaitCursor;
            //frmDBManager = FrmDBManage.CreateInstance;
            //frmDBManager.Show();
            //Cursor = Cursors.Default;
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            //Thread t1 = new Thread(new ThreadStart(ShowBar));
            //t1.Start();





            Cursor = Cursors.WaitCursor;
            //Statistics();
            //_bll.MoveData();
            Cursor = Cursors.Default;
        }

        private void ShowBar()
        {
            frmBar = new FrmProsessBar();
            frmBar.ShowDialog();
        }
        private void CloseFrmBar()
        {
            frmBar.Close();
        }
        private void Statistics()
        {
            _bll.Statistics();
            //frmBar.Close();
            this.Invoke(new CloseBar(CloseFrmBar));
            MessageBox.Show("统计完成！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            
        }

        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmTechCommomCharge = FrmTechCommomChargeItem.CreateInstance;
            frmTechCommomCharge.MdiParent = this;
            frmTechCommomCharge.WindowState = FormWindowState.Maximized;
            frmTechCommomCharge.Show();
        }

        private void navBarItemShippingManager_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
             CloseMDIForm();
             frmShippingManager = FrmShippingManager.CreateInstance;
             frmShippingManager.MdiParent = this;
             frmShippingManager.WindowState = FormWindowState.Maximized;
             frmShippingManager.Show();
        }

        private void navBarItem4_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            CloseMDIForm();
            frmSalesmanManager = FrmSalesmanManager.Instance;
            frmSalesmanManager.MdiParent = this;
            frmSalesmanManager.WindowState = FormWindowState.Maximized;
            frmSalesmanManager.Show();
        }

        private void navBarItem5_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
               CloseMDIForm();
               frmProductCommomItem = FrmProductCommomItem.Instance;
               frmProductCommomItem.MdiParent = this;
               frmProductCommomItem.WindowState = FormWindowState.Maximized;
               frmProductCommomItem.Show();
              
        }
        
        private void navBarItem6SubProductSet_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
             CloseMDIForm();
             frmComplexset = FrmComplexSet.Instance;
             frmComplexset.MdiParent = this;
             frmComplexset.WindowState = FormWindowState.Maximized;
             frmComplexset.Show();
        }

       


     
    }
}
